<template>
  <div>
    <router-link tag="div" to="/" class="header-icon" v-show="showHeader">
      <div class="iconfont back-icon">&#xe624;</div>
    </router-link>
    <div class="header-fixed" :style="styObj" v-show="!showHeader">
      景点详情
      <router-link to="/" tag="div" class="iconfont header-fixed-icon">&#xe624;</router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showHeader: true,
      styObj: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      let offsetY = document.documentElement.scrollTop
      if (offsetY > 60) {
        this.showHeader = false
        let opacity = (offsetY - 60) / 80
        this.styObj.opacity = opacity > 1 ? 1 : opacity
      } else {
        this.showHeader = true
      }
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  .header-icon
    position: absolute
    top: .2rem
    width: .8rem
    height: .8rem
    left: .2rem
    line-height: .8rem
    text-align: center
    border-radius: .4rem
    background: rgba(0, 0, 0, .8)
    .back-icon
      color: #fff
      font-size: .4rem
  .header-fixed
    z-index: 2
    position: fixed
    top: 0
    right: 0
    left: 0
    line-height: $height
    text-align: center
    height: $height
    color: #fff
    font-size: .32rem
    background: $bgColor
    .header-fixed-icon
      color: #fff
      position: absolute
      left: 0
      top: 0
      width: .64rem
      text-align: center
      font-size: .4rem
</style>
